package part15;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author wcj
 * @Date 2021/5/30 18:08
 * @Version 1.0
 */
public class Part1535 {

    public static void oldStyleMethod(List probablyDogs) {
        probablyDogs.add(new Cat());
    }

    /**
     * 动态类型检查：Collections提供了一系列的静态方法用来检查容器存储元素的正确性与否
     *
     * @param args
     */
    public static void main(String[] args) {
        ArrayList<Dog> dogs = new ArrayList<>();
        oldStyleMethod(dogs);
        List<Dog> dogs1 = Collections.checkedList(dogs, Dog.class);
        try {
            oldStyleMethod(dogs1);
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

class Cat {
}

class Dog {
}
